#pragma once


#include "Object/Object.h"
#include "Audio.m.h"


RCLASS()
class WHENGINE_API RAudio : public RObject
{
    ROBJECT

public:
    RAudio()=default;

public:
    RFUNCTION()
    int64_t GetNumChannels() const { return NumChannels; }

    RFUNCTION()
    int64_t GetSampleRate() const { return SampleRate; }
    
    RFUNCTION()
    int64_t GetByteRate() const { return ByteRate; }
    
    RFUNCTION()
    int64_t GetBlockAlign() const { return BlockAlign; }
    
    RFUNCTION()
    int64_t GetBitsPerSample() const { return BitsPerSample; }

    //return the length of the audio in seconds
    RFUNCTION()
    float GetLength() const;

    const TVector<uint8_t>& GetPCMData() const { return PCMData; }
    
    static RAudioPtr CreateAudio(
        RObject* InOwner
        , const TVector<uint8_t>& InPCMData
        , int64_t InNumChannels
        , int64_t InSampleRate
        , int64_t InBitsPerSample);

protected:

    RFIELD()
    uint16_t NumChannels; //number of channels
    RFIELD()
    uint32_t SampleRate; //sample rate
    RFIELD()
    uint32_t ByteRate; //byte rate
    RFIELD()
    uint16_t BlockAlign; //block align (bytes per sample= NumChannels * BitsPerSample/8) 
    RFIELD()
    uint16_t BitsPerSample; //bits per sample

    //PCM data
    RFIELD(SerializeAsBinary)
    TVector<uint8_t> PCMData;

    friend class RAudioSubsystem;
};